layui.use(['laydate','form','laytpl','gcate'], function(){
	var laydate = layui.laydate;
	var form = layui.form;
	var laytpl = layui.laytpl;
	var gcate = layui.gcate;
	var $ = layui.$;
	var ids = $('input[name="ids"]').val()
	var url = "/staff/order/index";

	var obj = {page:1, ids: ids};


	//执行一个laydate实例
	laydate.render({
	  	elem: '#start', //指定元素
	  	// type: 'datetime',
	});

	//执行一个laydate实例
	laydate.render({
	  	elem: '#end', //指定元素
	  	// type: 'datetime',
	});
	/*申明 列表查询及渲染*/
	list = function (){
		$.get(url,obj,function(msg){
			console.log(msg)
			if(msg.code != 1){
				layer.msg(msg.msg,{icon: 2})
				return false
			}
			var data = msg.msg 
			/*@表格*/
			var getTpl_1 = order_list.innerHTML;
			var list = document.getElementById('order-list');
			laytpl(getTpl_1).render(data, function(html){
				list.innerHTML = html;
			});
			/*@统计*/
			var getTpl_2 = order_count.innerHTML;
			var count = document.getElementById('order-count');
			laytpl(getTpl_2).render(data, function(html){
				count.innerHTML = html;
			});
			/*@分页*/
			var getTpl_3 = page_demo.innerHTML;
			var page = document.getElementById('page');
			laytpl(getTpl_3).render(data, function(html){
				page.innerHTML = html;
			});
		})
	}
	/*申明 时间判断*/
	ifTime = function(){
		var startDate = new Date($('input[name="start"]').val()).getTime(); 
  		var endTime = new Date($('input[name="end"]').val()).getTime(); 
  		if (endTime < startDate) { 
  			layer.msg('结束时间不能小于开始时间',{icon: 2});
  			return false;
  		}
	}
	/*申明 点击分页*/
	page = function (p){	
		obj.page = p;
		list()
	}
	/*执行 列表查询及渲染*/
	list()
	/*查询事件*/
	form.on('submit(sreach)',function(data) {
        obj = data.field
        obj.page = 1
        if(ifTime() == false) return false;
        list()
        return false;
    })
    /*@产品分类*/
	gcate.form.g_cate('select', '/staff/goods/sun_cate')
	
	
});